package com.igeek.car.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.car.constant.MessageConstant;
import com.igeek.car.entity.Refunds;
import com.igeek.car.result.Result;
import com.igeek.car.service.RefundsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import com.igeek.car.vo.PageQueryVO;
import org.springframework.web.bind.annotation.*;

/**
 * RefundsController 退票记录接口，仅仅只做接口暴露
 * RefundsService   退票记录业务
 *      RefundsServiceImpl  退票记录业务的具体实现
 * RefundsMapper   退票记录的持久层交互
 *
 * Swagger测试地址：http://localhost:8080/swagger-ui.html
 *
 * @author Suzi
 * @since 2024-12-05
 */
@RestController
@RequestMapping("/admin/refunds")
@Api(tags = "退票记录的接口管理")
public class RefundsController {

    @Autowired
    private RefundsService refundsService;

    @ApiOperation("分页条件查询退票记录")
    @GetMapping("findPage")
    public Result findPage(PageQueryVO vo){
        Page<Refunds> page = refundsService.findPage(vo);
        if(page != null){
            return new Result(true, MessageConstant.QUERY_REFUND_SUCCESS, page);
        }
        return new Result(false, MessageConstant.QUERY_REFUND_FAIL);
    }

    @ApiOperation("新增退票记录")
    @PostMapping("add")
    public Result add(@RequestBody Refunds refunds){
        boolean flag = refundsService.save(refunds);
        if(flag){
            return new Result(true, MessageConstant.ADD_REFUND_SUCCESS);
        }
        return new Result(false, MessageConstant.ADD_REFUND_FAIL);
    }

    @ApiOperation("通过ID查询退票记录信息")
    @GetMapping("{id}")
    public Result findOne(@PathVariable("id") Integer id){
        Refunds refunds = refundsService.getById(id);
        if(refunds != null){
            return new Result(true, MessageConstant.QUERY_REFUND_SUCCESS, refunds);
        }
        return new Result(false, MessageConstant.QUERY_REFUND_FAIL);
    }

    @ApiOperation("编辑退票记录")
    @PutMapping("update")
    public Result update(@RequestBody Refunds refunds){
        boolean flag = refundsService.updateById(refunds);
        if(flag){
            return new Result(true, MessageConstant.UPDATE_REFUND_SUCCESS);
        }
        return new Result(false, MessageConstant.UPDATE_REFUND_FAIL);
    }

    @ApiOperation("删除退票记录")
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        boolean flag = refundsService.del(id);
        if(flag){
            return new Result(true, MessageConstant.DELETE_REFUND_SUCCESS);
        }
        return new Result(false, MessageConstant.DELETE_REFUND_FAIL);
    }
}